#ifndef CDRAWSQL_H
#define CDRAWSQL_H

#include "progsql.h"
#include "CPokerServer.h"
#include "CPokerConnection.h"
#include "CDBInterface.h"


class CGame;
class CSavedGame;

//*****************************************************************************************************
//
//  This class handles the database access for the Caribbean Draw game.  It uses the single server
//  wide ProgressiveTrackSQL object to actually create odbc connections to the database, but the logic
//  of building the stored procedure requests and interpreting the returned result sets is done here.
//
//  This class is derived from CDBInterface, which exists to define the interface that the Connection 
//  class uses to communicate with these game-specific database access classes, and also holds some 
//  common logic.
//
//  There'll be an instance of this class for every player session on this poker server.
//
//  All money values are in cents (100 == $1, 25 == $.25, 1 == $.01)
//
//*****************************************************************************************************
class CDrawSQL : public CDBInterface
{
    public:
        CDrawSQL(ProgressiveTrackSQL *pTracker, CInfo *pInfo);

        // called everytime a new game is begun.
        bool8   trackNewGame(int32 Bet, int32 progressiveBet, int32 multiBankBet, 
                             int32* Balance, uint8 payTable, int32 compFactor);

        // called when the user requests that cards be dealt, usually right after trackNewGame.
        bool8   trackDeal(CGame *game);

        // called when the final status of a game has been determined.
        bool8   trackGameDone(bool8 Raised, int32 PayAnte, int32 PayRaise, int32 PayProgressive,
                              int32 PayMultiBank, int32 Outcome, int32 BalAdjust, int32 *Balance,
                              bool8 bMalfunction, CGame *pGame); 

        // called to load any saved game that the current user might have laying around.
        bool8   trackHasSavedGame(CPokerConnection *pConn, CGame ** ppGame, int32 * err);

        // called to (theoretically) save the game state to the database after the cards are dealt.
        bool8   trackSaveGame(CGame *pGame);

        // called to load the casino settings for Caribbean Draw.
        bool8   trackGetOptions(bool8* progressiveOn, uint8* progPayTable, 
                                int32* progJackpotID, uint8* payTable, int32* progressiveFixAmountMultiplier);

    protected:

         // actually does the database work of ceating a new game...called by trackNewGame.
        int32 createGame(int32 casinoId, const PID&, bool8 forMoney, SESSIONID, int32 compFactor,
                         CPokerGameID, int32 bet, int32 progressiveBet,
                         int32 multiBankBet, int32* balance, int32* comp, 
                         uint8 payTable);

        // actually does the database work of tracking the the dealt cards...called by trackDeal.
        int32 deal(const PID&, CPokerGameID, int32 nDeckSeed, int32 numDealer, uint8* dealer, int32 numPlayer, uint8* player);

        // actually does the database work of recording a completed game...called by trackGameDone.
        int32 gameDone(int32 casinoId, const PID&, bool8 forMoney, CPokerGameID, bool8 raised,
                       int32 payAnte, int32 payRaise, int32 payProgressive, int32 payMultiBank, 
                       int32 outcome, int32 balanceAdjust, int32* balance, int32* comp, bool8 bMalfunction,
                       int32 numDealer1, uint8* dealer1, int32 numDealer2, uint8* dealer2, int32 numPlayer, 
                       uint8* player, uint8 ucDealerDraw, uint8 ucPlayerDraw);

        // actually does the work of checking the database for saved games...called by trackSaveGame.
        int32 hasSavedGame(const PID&, bool8 forMoney, CPokerGameID, CSavedGame*, bool8* exists);

        // could theoretically do the work of saving the game state to the database...actually does nothing.
        // called by trackSaveGame.
        int32 saveGame(const PID&, bool8 forMoney, CPokerGameID, CSavedGame*);

        // does the actual work of loading the casino settings for Caribbean Draw...called from trackGetOptions.
		int32 getOptions(bool8* progressiveOn, uint8* progPayTable,
						int32* progJackpotID, uint8* payTable, int32* progressiveFixAmountMultiplier);

};

#endif
